package com.da.javalog.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * 参数校验工具类
 */
public class AssertUtils {

    /**
     * 不能为NULL
     *
     * @param obj
     */
    public static void notNull(Object obj) {
        if (obj == null) {
            throw new RuntimeException("args must not be null");
        }
    }

    public static void notNull(Object... args) {
        if (args != null && args.length > 0) {
            for (Object obj : args) {
                if (obj == null) {
                    throw new RuntimeException("args must not be null");
                }
            }
        }
    }

    public static void notNull(Object obj, String msg) {
        if (obj == null) {
            throw new RuntimeException(msg);
        }
    }

    public static void notNullAndMsg(Object obj, String fieldName) {
        if (obj == null) {
            throw new RuntimeException("[" + fieldName + "] 参数不能为空");
        }
        if (obj instanceof String) {
            if (StringUtils.isEmpty((String) obj)) {
                throw new RuntimeException("[" + fieldName + "] 参数不能为空");
            }
        }
    }

    public static void assertTrue(boolean state, String msg) {
        if (!state) {
            throw new RuntimeException(msg);
        }
    }

    public static <T> boolean isNotEmpty(T[] arrays) {
        return arrays != null || arrays.length > 0;
    }

    public static boolean isNotEmpty(int[] arrays) {
        return arrays != null || arrays.length > 0;
    }
}